import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * The Main class that executes and terminates the program.
 */
public class Main {
	
	/**
	 * Runs the program, and terminates when all the reindeer are completed.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {

		CountDownLatch startSignal = new CountDownLatch(1);

		List<Reindeer> reindeers = new ArrayList<Reindeer>();
		for (int i = 0; i < Properties.TOTAL_REINDEER; i++) {
			Reindeer reindeer = new Reindeer(Properties.REINDEER_NAMES[i],
					startSignal);

			reindeer.start();

			reindeers.add(reindeer);
		}

		for (int i = 0; i < Properties.TOTAL_ELVES; i++) {
			Elf elf = new Elf("Elf " + i, startSignal);
			elf.start();
		}

		Santa santa = new Santa(startSignal);
		santa.start();

		startSignal.countDown();

		for (Reindeer reindeer : reindeers) {

			try {
				reindeer.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}

		}
		System.exit(0);
	}

}
